package cn.anlab.anappframe;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;

import cn.anlab.anappframe.net.IOErrorListener;
import cn.anlab.anappframe.net.IOServer;
import cn.anlab.anappframe.net.JsonIOHandler;
import cn.anlab.anappframe.net.Packet;
import cn.anlab.anappframe.net.ReceiveCallback;
import cn.anlab.anappframe.util.Log;

public class Test {
	
	public static void main(String[] args) throws IOException {
		
		final IOServer server = new IOServer();
		server.setHandler(new JsonIOHandler());
		server.setIoErrorListener(new IOErrorListener() {
			@Override
			public void onError(int ErrorType, Exception e) {
				Log.e("anlog", "exception : " + e.getMessage());
			}
		});
		server.setReceiveCallback(new ReceiveCallback<Packet>() {
			
			@Override
			public void onReceive(InetSocketAddress from, Packet p) {
				Log.e("anlog", "packet : " + p.toString());
				Map m = new HashMap();
				m.put("msg", "Hello Boy.");
				m.put("userKey", "123456");
				Packet pp = new Packet(20120011, m);
				server.send(from, pp);
			}
		});
		server.start();
		
	}

}
